$(function() {
	
 
	//用户信息注册
	$("#btnSave").click(function() {
		init();
		var email=$("#email").val();
		$.get("../webemail/checkMultiEmail.action?email="+email,function(data){ 
			var successFlag=data.checkFlag;
			if(successFlag==true){
				var password=$("#password").val();
				var passwordSure=$("#passwordSure").val();
				if(password != passwordSure){
					var passwordSureErrorMsg=$("#passwordSureErrorMsg").val();
					document.getElementById("warm").innerHTML="<font color='red'>"+passwordSureErrorMsg+"</font>";
					document.getElementById("passwordSure").focus();
				    return;
				}
				else{
				document.forms[0].action ="../webcom/registerUser.action";
				document.forms[0].submit();	
			}}
			else{
				 var emailAgainMsg=$("#emailAgainMsg").val();
				document.getElementById("emailWarm").innerHTML="<font color='red'>"+emailAgainMsg+"</font>";
				document.getElementById("email").focus();
				return;
			}
		},"json");
		
	});
	
	$("#btnEdit").click(function() {
		var password=$("#password").val();
		var passwordSure=$("#passwordSure").val();
		if(password != passwordSure){
			var passwordSureErrorMsg=$("#passwordSureErrorMsg").val();
			document.getElementById("warm").innerHTML="<font color='red'>"+passwordSureErrorMsg+"</font>";
			document.getElementById("passwordSure").focus();
		    return;
		}
		else{
		
		        init();
				document.forms[0].action ="../webcom/updateUser.action";
				document.forms[0].submit();	
		}
	});
	
	$("#btnReturn").click(function() {

		document.forms[0].action ="../webgoods/homePageInit.action";
		document.forms[0].submit();
	
	});
	
	
});
	
function init(){
	var selYear=$("#selYear").val();
	var selMonth=$("#selMonth").val();
	var selDay=$("#selDay").val();
	if(selMonth.length == 1){
		var month="0" + selMonth;
		selMonth=month;
	}
	if(selDay.length == 1){
		var day="0" + selDay;
		selDay=day;
	}
	$("#birthday").val(selYear+"-"+selMonth+"-"+selDay);
	if($('input:radio[name="sexForUser"]:checked')){
		var radioValue =$('input:radio[name="sexForUser"]:checked').val();
		$("#sex").val(radioValue);
	}
}

function clear(){
	$("#nameKanJiSei").val("");
	$("#nameKanJiMei").val("");
	$("#nameKatakanaSei").val("");
	$("#nameKatakanaMei").val("");
	$("#nameEnFamily").val("");
	$("#nameEnMiddle").val("");
	$("#nameEnLast").val("");
	$("#birthday").val("");
	$("#email").val("");
	$("#tel").val("");
	$("#password").val("");
	$("#sex").val("");
	$("#selfIntroduction").val("");
	$("#zipCode").val("");
	$("#addProvince").val("");
	$("#addCity").val("");
	$("#addOther").val("");
}

function insertAgain(){
	var password=$("#password").val();
	var passwordSure=$("#passwordSure").val();
	if(password != passwordSure){
		var passwordSureErrorMsg=$("#passwordSureErrorMsg").val();
		document.getElementById("warm").innerHTML="<font color='red'>"+passwordSureErrorMsg+"</font>";
	    return;
	}
	else{
		document.getElementById("warm").innerHTML="";
	}
}

function insertPassword(){
	var password=$("#password").val();
	if(password.length>0){
		document.getElementById("passwordwarm").innerHTML="";	
	}
	
}

function multCheck(){
	var email=$("#email").val();
	$.get("../webemail/checkMultiEmail.action?email="+email,function(data){ 		
	    checkInit(data);
	},"json");
}

function checkInit(data){
	var checkFlag=data.checkFlag;
	if(checkFlag==false){
		 var emailAgainMsg=$("#emailAgainMsg").val();
		document.getElementById("emailWarm").innerHTML="<font color='red'>"+emailAgainMsg+"</font>";
	    return;
	}
	else{
		document.getElementById("emailWarm").innerHTML="";
	}
}
